/**
 * 扫描功能
 */
import React, { Component } from 'react';
import {
    AppRegistry,
    Dimensions,
    StyleSheet,
    Text,
    TouchableHighlight,
    View,
    BackAndroid,
    Platform
} from 'react-native';
import Camera from 'react-native-camera';

export default class BadInstagramCloneApp extends Component {

    constructor(props) {
        super(props);
        this.state = {};
        this.back=this.back.bind(this)
    }
    render() {
        return (
            <View style={styles.container}>
                <Camera
                    ref={(cam) => {
                        this.camera = cam;
                    }}
                    style={styles.preview}
                    onBarCodeRead={(e)=>{alert(e.data)}}
                    aspect={Camera.constants.Aspect.fill}>
                </Camera>
            </View>
        );
    }

    componentDidMount() {
        // this.props.tabBar.hide();
    }

    componentWillMount () {
        if (Platform.OS === 'android') {
            BackAndroid.addEventListener('hardwareBackPress', this.back);
        }
    }

    componentWillUnmount(){
        if (Platform.OS === 'android') {
            BackAndroid.removeEventListener('hardwareBackPress', this.back);
        }
        // this.props.tabBar.show();
    }

    back(){
        this.props.navigation.goBack();
        return true;
    }
    static navigationOptions = {
        headerTitle:'扫描二维码',
    };
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        flexDirection: 'row',
    },
    preview: {
        flex: 1,
        justifyContent: 'flex-end',
        alignItems: 'center'
    },
});